<?php
class Jabatan_model extends MY_Model {
	
    function Jabatan_model(){
        parent::MY_Model();
        $this->load->database();
        $this->table_name = "jabatan";
    }
    
    function select_last_entry($search_key=false, $where=false, $limit=10, $offset=0, $orderby=""){
    	$sql = $sqlo = $sqlw = "";
    	
    	$sqlw = "WHERE a.dep_id = b.dep_id";
    	if ($search_key){
    		$sqlw .= ($sqlw? " AND " : ""). 
    				"(a.jbt_id LIKE '%$search_key%' OR 
    				 a.jbt_nama LIKE '%$search_key%' OR
    				 a.jbt_level LIKE '%$search_key%' OR
    				 b.dep_id LIKE '%$search_key%' OR
    				 b.dep_nama LIKE '%$search_key%')";
    	}
    	if ($where){
    		$sqlw .= ($sqlw? " AND " : "").$where;
    	}
    	
    	if ($orderby){
    		$sqlo = "ORDER BY $orderby";
    	}
    	return $query = $this->db->query(
    		"SELECT a.jbt_id, a.jbt_nama, b.dep_id, b.dep_nama, a.jbt_level 
    		FROM ".$this->table_name." as a, departemen as b 
  			$sqlw 
    		$sqlo 
    		LIMIT $offset,$limit");
    }
        
    function select_by_id($id, $orderby=false){
    	if ($orderby) $this->db->order_by($orderby);
    	$this->db->select('*');
		$this->db->join('departemen', 'departemen.dep_id = '.$this->table_name.'.dep_id');
    	return $query = $this->db->get_where($this->table_name, array('jbt_id' => $id));
    }
}